using System;
using System.Drawing;

using SdlDotNet.Graphics;

using Game.Input.Devices;
using Game.Utils;
using Game.World;
using Game.Output;

namespace Game.Input.GUI
{
	public class CTileIndicator
	{
		private CCountry	m_country;
		
		private Surface	m_surface;
		private Point	m_position;
		
		private Point	m_tileCoords;
		private bool	m_isHidden;

		public CTileIndicator(CCountry p_country)		
		{
			m_country = p_country;
			
			Initialize();
		}
		
		public void Initialize()
		{
			CConsole.ReportClassInit(System.Reflection.MethodInfo.GetCurrentMethod().DeclaringType.Name);
			
			CSurfaceFactory.CreateSurface(out m_surface, new Size(100, 100));
			
			m_position = CMouseHandler.MouseInfo.position;
		}
		
		public void Update()
		{
			Point m = CMouseHandler.MouseInfo.position;
			
			Point o = new Point();
			
			o.X = m_country.Position.X + m_country.Origin.X; 
			o.Y = m_country.Position.Y + m_country.Origin.Y;
			
			m_tileCoords = new Point(
				(int)((m.X + 2  *             m.Y - o.X - 2 * o.Y) / 64.0f),
				(int)((o.X + 32	* ((m.X + 2 * m.Y - o.X - 2 * o.Y) / 64.0f) - m.X) / 32.0f)
			);
			
			m_isHidden = false;
			
			m_position = new Point(
				-32 + m_country.Position.X + m_country.Origin.X + m_tileCoords.X * 32 - m_tileCoords.Y * 32,
				0   + m_country.Position.Y + m_country.Origin.Y + m_tileCoords.X * 16 + m_tileCoords.Y * 16
			);
		}
		
		public void Render(ref Surface p_surface)
		{
			p_surface.Blit(m_surface, m_position);
		}
		
		#region properties
		
		public Point Position
		{
			get {
				return m_position;
			}
		}
		
		public Point TileCoords
		{
			get {
				return m_tileCoords;
			}
		}
		
		public bool IsHidden
		{
			get {
				return m_isHidden;
			}
		}
		
		#endregion
	}
}
